package fr.inria.arles.temperatureManagement.queryProcessor.query;

import java.sql.ResultSet;
import java.sql.SQLException;

import static fr.inria.arles.temperatureManagement.utility.Utility.*;

/**
 * A Query to authenticate the user.
 */
public class AuthenQuery extends AbstractQuery {

    /*
     * (non-Javadoc)
     *
     * @see
     * fr.inria.arles.tempManagement.queryProcessor.query.AbstractQuery#execute
     * (java.lang.String[])
     */
    @Override
    public String execute(String[] args) throws ClassNotFoundException,
            SQLException {
        ResultSet rs = executeQuery(
                "SELECT ID FROM TEMPERATURE WHERE USERNAME=? "
                + "AND PASSWORD=? AND PARTITION=?",
                args);
        if (rs.next()) {
            return encode("true", rs.getLong("ID") + "");
        } else {
            return encode("true", "-1");
        }
    }
}
